#Requires AutoHotkey v2.0
#include hotkey.ahk

if FileExist("local.ini")
    load_cfg("local.ini")

; 设置笔记目录
EnvSet("NotePath", "D:\doc\notes\")

; 创建笔记
create_note(file_name, title:="", content:=""){
    file := EnvGet("NotePath") title file_name
    head := "# " repeat_char("-", 132) "`n"
    head .= "# " FormatTime(, "yyyy-MM-dd HH-mm-ss") FormatTime(, "(ddd)") "`n`n"
    if title != ""{
        head .= "# " title "`n"
    }
    fp := FileOpen(file, "a")
    fp.Write(head)
    fp.Write(content)
    fp.Close()
    return file
}

; # :win 键
; ! :alt
; ^ :ctrl
; + :shift

; ctrl+alt+n        保存网页为笔记
^!n::{
    ib := InputBox("输入笔记名:", "创建笔记", "W150 H100")
    if ib.Result = "Cancel"
        return
    Send "^c"
    RunWait("python common\action.py format", A_WorkingDir, "Hide")
    ; file_name := FormatTime(, "yyyyMMdd_HHmmss") ".memo"
    file_name := ".memo"
    note_path := create_note(file_name, ib.Value, A_Clipboard)
    RunWait "nvim-qt.exe " note_path
}
; alt+n             打开笔记
!n::{
    RunWait "nvim-qt.exe " EnvGet("NotePath") "todolist.memo"
}
